package net.pws.oos.biz.model;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "s_organization")
public class Organization extends Identifier {
    
	private static final long serialVersionUID = 4616242652716797253L;
	
	public static final int INNER_CODE_DEPTH = 6;
    public static final int INNER_CODE_UNIT_LENGTH = 5;
    public static final char INNER_CODE_FILL = '0';
    
    private String name;
    
    @Column(name = "short_name")
    private String shortName;
    
    private String code;
    
    private String description;
    
    @Column(name = "district_code")
    private String districtCode;

    @Column(name = "district_name")
    private String districtName;
    
    private BigDecimal longitude;
    
    private BigDecimal latitude;
    
    @Column(name = "zoom_level")
    private int zoomLevel;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    private Organization parent;
    
    private int depth = 0;
    
    @Column(name = "inner_code")
    private String innerCode;
    
    @OneToMany(mappedBy = "parent")
    private Set<Organization> children = new HashSet<Organization>();
    
    private boolean leaf = true;

    @Column(name = "has_deleted")
    private Boolean deleted = Boolean.FALSE;

    @Column(name = "source_id")
    private String sourceId;
    
    @Column(name = "source_system")
    private String sourceSystem;
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getShortName() {
        return shortName;
    }
    
    public void setShortName(String shortName) {
        this.shortName = shortName;
    }
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public Organization getParent() {
        return parent;
    }
    
    public void setParent(Organization parent) {
        this.parent = parent;
    }
    
    public int getDepth() {
        return depth;
    }
    
    public void setDepth(int depth) {
        this.depth = depth;
    }
    
    /**
     * 内部编码，形成树形结构<br>
     * 暂时维护6级，每级编码5位，共30位。
     * 深度从0开始，因为内部编码的有效位数取前(depth+1)*5
     * @return
     */
    public String getInnerCode() {
        return innerCode;
    }
    
    public void setInnerCode(String innerCode) {
        this.innerCode = innerCode;
    }
    
    public String getDistrictCode() {
        return districtCode;
    }

    public void setDistrictCode(String districtCode) {
        this.districtCode = districtCode;
    }

    public String getDistrictName() {
        return districtName;
    }

    public void setDistrictName(String districtName) {
        this.districtName = districtName;
    }

    public BigDecimal getLongitude() {
        return longitude;
    }
    
    public void setLongitude(BigDecimal longitude) {
        this.longitude = longitude;
    }
    
    public BigDecimal getLatitude() {
        return latitude;
    }
    
    public void setLatitude(BigDecimal latitude) {
        this.latitude = latitude;
    }
    
    public int getZoomLevel() {
        return zoomLevel;
    }
    
    public void setZoomLevel(int zoomLevel) {
        this.zoomLevel = zoomLevel;
    }
    
    public boolean isLeaf() {
        return leaf;
    }
    
    public void setLeaf(boolean leaf) {
        this.leaf = leaf;
    }
    
    public Set<Organization> getChildren() {
        return children;
    }
    
    public void setChildren(Set<Organization> children) {
        this.children = children;
    }

    public Boolean getDeleted() {
        return deleted;
    }
    
    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public String getSourceSystem() {
        return sourceSystem;
    }

    public void setSourceSystem(String sourceSystem) {
        this.sourceSystem = sourceSystem;
    }
    
}
